package com.miya.lib_common.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author robin 2023-06-10 created
 */
public class UtilsFactory {

    private Executor executor;
    private static UtilsFactory instance;

    public static UtilsFactory getInstance() {
        if (instance == null) {
            instance = new UtilsFactory();
            instance.executor = Executors.newFixedThreadPool(20);
        }
        return instance;
    }

    public void runOnAsync(Runnable runnable) {
        executor.execute(runnable);
    }


    public final AppConfig appConfig = new AppConfig();

    public void loadConfig(Context context) {
        SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        appConfig.isFirstStart = sp.getBoolean("isFirstStart", true);
    }

    public void save(Context context) {
        SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        sp.edit()
                .putBoolean("isFirstStart", appConfig.isFirstStart)
                .apply();
    }
}

